package dk.aau.walkietalkie.audio;

import java.io.IOException;

import android.media.MediaPlayer;
import android.os.Environment;
import android.util.Log;

//public class VoicePlayer{
//	
//	private static final String LOG_TAG = "AudioRecorderExample";
//	private MediaPlayer mPlayer;
//	private String mFileName = Environment.getExternalStorageDirectory().getAbsolutePath()+"/audiorecordtest.3gp";
//
//	public void startPlaying() {
//		mPlayer = new MediaPlayer();
//		try {
//			mPlayer.setDataSource(mFileName);
//			mPlayer.prepare();
//			mPlayer.start();
//		} catch (IOException e) {
//			Log.e(LOG_TAG, "prepare() failed");
//		}
//	}
//public  void stopPlaying() {
//		mPlayer.release();
//		mPlayer = null;
//	}
//	
//}

public class VoicePlayer {
	private String VOICE_PATH = Environment.getExternalStorageDirectory()
			.getAbsolutePath() + "/audiorecordtest.3gp";
	// private static final String VOICE_PATH = Environment
	// .getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)
	// .getPath()
	// + "/tmp_audio.jpg";
	private MediaPlayer mPlayer = null;
	private static final String LOG_TAG = "VoicePlayer";

	public void startPlaying(String mFilePath) {
		if ("".equals(mFilePath)) {
			mFilePath = VOICE_PATH;
		}
		try {
			if (mPlayer != null) {
				mPlayer.reset();
			}
			mPlayer = new MediaPlayer();
			mPlayer.setDataSource(mFilePath);
			mPlayer.prepare();
			mPlayer.start();
		} catch (IOException e) {
			Log.e(LOG_TAG,
					"Playback of " + mFilePath + " failed: " + e.getMessage());
		}
	}

	public void stopPlaying() {
		mPlayer.release();
		mPlayer = null;
	}
}
